package game.module.mail.processor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.common.PlayingRoleMsgProcessor;
import game.entity.PlayingRole;
import game.module.mail.logic.MailManager;
import lion.common.MsgCodeAnn;
import lion.netty4.message.MyRequestMessage;
import lion.netty4.message.RequestMessageRaw;
import lion.netty4.message.RequestProtoMessage;
import lua.LuaMessageHall.C2SMailList;
import lua.LuaMessageHall.S2CMailList;

/**
 * @author: Pomelo.Lee
 * @date: 2017年8月24日 下午5:15:51
 */
@MsgCodeAnn(msgcode = C2SMailList.id, accessLimit = 500)
public class MailListProcessor extends PlayingRoleMsgProcessor {

	private static Logger logger = LoggerFactory.getLogger(MailListProcessor.class);

	@Override
	public void process(PlayingRole playingRole, RequestMessageRaw requestMessage) throws Exception {
		C2SMailList reqMail = C2SMailList.parse(requestMessage);
		int playerId = playingRole.getId();
		logger.info("playerId={},lastMailId={}", playerId, reqMail.last_mail_id);
		S2CMailList respMsg = new S2CMailList();
		respMsg.mail_list = MailManager.getInstance().listMail(playerId, reqMail.last_mail_id);
		playingRole.writeAndFlush(respMsg.build(playingRole.alloc()));
	}

	@Override
	public void processProto(PlayingRole playingRole, RequestProtoMessage request) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void processWebsocket(PlayingRole playingRole, MyRequestMessage request) throws Exception {
		// TODO Auto-generated method stub

	}

}
